
class AsyncManager(object):
    def __init__(self):
        pass
    def start(self):
        pass
    def stop(self):
        pass
    def add(self, ios):
        pass
    
class AsyncIOBase(object):
    pass

class TelnetConnection(object):
    def __init__(self):
        pass
    def connect(self):
        pass
    def close(self):
        pass
    def set_handler(self, opt, hand):
        pass
    def send_data(self, data):
        pass
    def send_cmd(self, cmd):
        pass
    def on_recv_data(self, data):
        pass
    def on_recv_cmd(self, cmd):
        pass
    def _on_recv(self):
        data = self.recv(BUFFER_SIZE)
        
        for xfrm in self.xfrms:
            data = xfrm(data)
##        jdx = data.find(IAC)
##        if jdx == -1:
##            self.on_recv_data(data)
##            return
        idx = 0
        end = len(data)
        while idx < end:
            if state == 0:
                jdx = data.find(TEL_IAC, idx)
                if jdx == -1:
                    if not urgent:
                        if idx == 0:
                            self.on_recv_data(data)
                        else:
                            self.on_recv_data(data[idx:])
                    break
                if not urgent:
                    self.on_recv_data(data[idx:jdx])
                state = 1
                idx = jdx
            elif state == 1:
                val = data[idx]
                if val == TEL_IAC:
                    self.on_recv_data(val)
                    state = 0
                elif val >= TEL_SB:
                    cmds.append(TelnetCommand(val))
                    state = 2
                else:
                    if val in self.cmd_map:
                        if self.cmd_map[val]():
                            cmds.append(TelnetCommand(val))
                    else:
                        ctrls.append(TelnetError())
                    state = 0
            elif state == 2:
                cmd.opt = data[idx]
                if cmd.val == TEL_SB:
                    state = 3
                else:
                    state = 0
                    handle_cmd
            elif state == 3:
                jdx = data.find(TEL_IAC, idx)
                if jdx == -1:
                    cmd.arg += data[idx:]
                    pass
                cmd.arg += data[idx:jdx]
                state = 4
            elif state == 4:
                val = data[idx]
                if val == TEL_IAC:
                    cmd.arg += val
                    state = 3
                elif val == TEL_SE:
                    state = 0
                    handle_cmd
                else:
                    # what to do with invalid IAC command inside
                    # of an IAC SB sequence?
                    
            idx += 1
            chunk = data[idx : jdx]
            chunks.append(chunk)
            self.telcmd = TelnetCommand()
            if jdx
            if data.find(
        